<template>
<!-- 检验规则维护（按照品号）弹窗 -->
  <p-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">
        <p-row>
		  <p-col  :span="12">
			<p-form-item label="产品/物料编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="basic-business"
						v-decorator="['mcode', validatorRules.mcode]"
						:trigger-change="true"
						org-fields="mid,mcode,mname,sprc"
						dest-fields="mid,mcode,mname,sprc"
						code="mes_ba_cpinfo_main"
						:add="this.url.add"
						isMultiSelect="popup"
						@oNvisible="oNvisible"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="产品/物料名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input class="ant-input " v-decorator="[ 'mname', validatorRules.mname]" placeholder="请输入产品/物料名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="产品/物料一级分类编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="basic-business"
						v-decorator="['mbcode', validatorRules.mbcode]"
						:trigger-change="true"
						org-fields="mtypeno,mtypename"
						dest-fields="mbcode,mbname"
						code="mes_ba_cptype1"
						:add="this.url.add"
						isMultiSelect="popup"
						@oNvisible="oNvisible"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="产品/物料一级分类名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input class="ant-input " v-decorator="[ 'mbname', validatorRules.mbname]" placeholder="请输入产品/物料一级分类名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="产品/物料二级分类编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="basic-business"
						v-decorator="['mscode', validatorRules.mscode]"
						:trigger-change="true"
						org-fields="mtypeno,mtypename"
						dest-fields="mscode,msname"
						code="mes_ba_cptype2"
						:add="this.url.add"
						isMultiSelect="popup"
						@oNvisible="oNvisible"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="产品/物料二级分类名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input class="ant-input " v-decorator="[ 'msname', validatorRules.msname]" placeholder="请输入产品/物料二级分类名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="检验类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['inspectionType', validatorRules.inspectionType]" :trigger-change="true" dictCode="inspect_type" placeholder="请选择检验类型"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="工艺路线名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'processRouteName', validatorRules.processRouteName]" placeholder="请输入工艺路线名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="供应商编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input class="ant-input " v-decorator="[ 'custno', validatorRules.custno]" placeholder="请输入供应商编码"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="供应商名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="basic-business"
						v-decorator="['custname', validatorRules.custname]"
						:trigger-change="true"
						org-fields="supid,supno,supname"
						dest-fields="custid,custno,custname"
						code="ba_supinfo"
						:add="this.url.add"
						isMultiSelect="popup"
						@oNvisible="oNvisible"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="radio" v-decorator="['status', validatorRules.status]" :trigger-change="true" dictCode="mes_status" placeholder="请选择状态"/>
			</p-form-item>
		  </p-col>
        </p-row>


      </p-form>
    </p-spin>
  </p-modal>
</template>

<script>


  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"

  export default {
    name: "MesQcInspectRuleBymcodeModal",
	mixins: [SubmitOnchangMixin],
    components: { 
      JDictSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width: 1200,
        labelCol: {
          xs: { span: 24 },
          sm: { span: 8 },
        },
        visible: false,
        model: {},
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        mcode:{rules: [{ required: false, message: '请输入产品/物料编码!' }]},
        mname:{rules: [{ required: false, message: '请输入产品/物料名称!' }]},
        mbcode:{},
        mbname:{},
        mscode:{},
        msname:{},
        inspectionType:{rules: [{ required: false, message: '请输入检验类型!' }]},
        processRouteName:{rules: [{ required: false, message: '请输入工艺路线名称!' }]},
        custno:{rules: [{ required: false, message: '请输入供应商编码!' }]},
        custname:{rules: [{ required: false, message: '请输入供应商名称!' }]},
        status:{rules: [{ required: false, message: '请输入状态!' }]},
        },
        url: {
          add: '/mes-quality/mesQcInspectRuleBymcode/add',
          edit: '/mes-quality/mesQcInspectRuleBymcode/edit',
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
				this.edit({});
				this.model.status = 1;
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'mcode','mname','mbcode','mbname','mscode','msname','inspectionType','processRouteName','custno','custname','status','createBy','createTime','updateBy','updateTime','remark'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
		handleOk () {
			const that = this;
			// 触发表单验证
			this.form.validateFields((err, values) => {
			  if (!err) {
				  that.confirmLoading = true;
				  let httpurl = '';
				  let method = '';
				  let formData = Object.assign(this.model, values);
				  this.formData = Object.assign(this.model, values);
				  //新增触发
				  if(!this.model.id){
					httpurl+=this.url.add;
					method = 'post';
					if(this.EnhanceJS.afterAdd){
					  //新增之前
					  let Obj = eval(this.EnhanceJS.afterAdd)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }else{
					//编辑触发
					httpurl+=this.url.edit;
					method = 'put';
					if(this.EnhanceJS.afterEdit){
					 //编辑之前
					  let Obj = eval(this.EnhanceJS.afterEdit)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }
			  }

			})
		},
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'mcode','mname','mbcode','mbname','mscode','msname','inspectionType','processRouteName','custno','custname','status','createBy','createTime','updateBy','updateTime','remark'))
      },

      
    }
  }
</script>
